import { defineStore } from 'pinia'

export const useMainStore = defineStore('main', {
  state: () => ({
    user: null,
    isLoggedIn: false,
    games: [],
    loading: false
  }),
  getters: {
    getUser: (state) => state.user,
    getGames: (state) => state.games,
    isLoading: (state) => state.loading
  },
  actions: {
    setUser(user) {
      this.user = user
      this.isLoggedIn = !!user
    },
    setGames(games) {
      this.games = games
    },
    setLoading(status) {
      this.loading = status
    },
    logout() {
      this.user = null
      this.isLoggedIn = false
    }
  }
})